package com.demo.demoproject.enums;

import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public enum Gender {
    UNKNOWN(0),
    MALE(1),
    FEMALE(2);

    private final int value;

    // 构造函数
    Gender(Integer value) {
        this.value = value;
    }

    /**
     * 获取枚举对应的值
     * @return 枚举对应的值
     */
    public Integer getValue() {
        return value;
    }

    /**
     * 根据值获取枚举常量
     * @param value 性别代表的值
     * @return 值对应的性别
     */
    @NotNull
    public static Gender getGenderByValue(Integer value) {
        for (Gender gender : Gender.values()) {
            if (Objects.equals(gender.getValue(), value)) {
                return gender;
            }
        }
        throw new IllegalArgumentException("Unknown value: " + value);
    }
}
